Saturday, May 30, 2020

               How to Use an RGB LED





click here :- https://amzn.to/2Ap2kN3





click here :- https://amzn.to/2Ap2kN3



click here :- https://amzn.to/2Ap2kN3

RGB CODE

int ledPinR = 11;   // the number of the LED R pin
int ledPinG = 10;   // the number of the LED G pin
int ledPinB = 9;    // the number of the LED B pin

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPinR, OUTPUT);
  pinMode(ledPinG, OUTPUT);
  pinMode(ledPinB, OUTPUT);
}

void loop() {
  int adcValue;     // Define a variable to save the ADC value
  // Convert analog of A0 port into digital, and work as PWM duty cycle of ledPinR port
  adcValue = analogRead(A0);
  analogWrite(ledPinR, map(adcValue, 0, 1023, 0, 255));
  // Convert analog of A1 port into digital, and work as PWM duty cycle of ledPinG port
  adcValue = analogRead(A1);
  analogWrite(ledPinG, map(adcValue, 0, 1023, 0, 255));
  // Convert analog of A2 port into digital, and work as PWM duty cycle of ledPinB port
  adcValue = analogRead(A2);
  analogWrite(ledPinB, map(adcValue, 0, 1023, 0, 255));
}




Wednesday, May 27, 2020


Guide for Relay Module with Arduino






This article shows how to control mains voltage with the Arduino
using a relay module. We make a brief introduction to the relay module
and build a simple project example with the Arduino. The example we’ll build
shows how to control a relay module with an Arduino and a PIR motion sensor.


Introducing the Relay Module

A relay is an electrically operated switch that can be turned on or off,
letting the current go through or not, and can be controlled with low voltages,
like the 5V provided by the Arduino pins.
Controlling a relay module with the Arduino is as simple as controlling any
other output as we’ll see later on.
This relay module has two channels (those blue cubes).
There are other models with one, four and eight channels.
This module should be powered with 5V, which is appropriate to use with an Arduino.
There are other relay modules that are powered using 3.3V, which is ideal for ESP32,
ESP8266, and other microcontrollers

Mains voltage connections

The high-voltage side has two connectors, each with three sockets: common
(COM), normally closed (NC), and normally open (NO).
relay-labeled
  • COM: common pin

  • NC (Normally Closed): the normally closed configuration is used when

you want the relay to be closed by default, meaning the current is flowing
unless you send a signal from the Arduino to the relay module to open the
circuit and stop the current.
NO (Normally Open): the normally open configuration works the other











way around: the relay is always open, so the circuit is broken unless you send a signal from the Arduino to close the circuit.
If you just want to light up a lamp occasionally, it is better to use a normally-open circuit configuration.

Example: Controlling a Lamp with a Relay Module and PIR Motion Sensor

In this example, we create a motion sensitive lamp. A lamp lights up for 10 seconds
every time motion is detected.
Motion will be detected using a If you are not familiar with the PIR
motion sensor, you can read the following post:



To control the lamp with mains voltage we’ll use a in normally-open
configuration.

Safety warning

Before proceeding with this project, I want to let you know that you’re dealing with mains
voltage. Please read the safety warning below carefully.
Warning: when you are making projects that are connected to mains voltage, you really
need to know what you are doing, otherwise you may shock yourself. This is a serious topic,
and we want you to be safe. If you’re not 100% sure what you are doing,
do yourself a favor and don’t touch anything. Ask someone who knows!

Parts required

Here’s the needed parts for this example:



clike here:-https://amzn.to/2AiUu7G



Code


// Relay pin is controlled with D8. The active wire is connected to Normally Closed and common
int relay = 8;
volatile byte relayState = LOW;

// PIR Motion Sensor is connected to D2.
int PIRInterrupt = 2;

// Timer Variables
long lastDebounceTime = 0;  
long debounceDelay = 10000;

void setup() {
  // Pin for relay module set as output
  pinMode(relay, OUTPUT);
  digitalWrite(relay, HIGH);
  // PIR motion sensor set as an input
  pinMode(PIRInterrupt, INPUT);
  // Triggers detectMotion function on rising mode to turn the relay on, if the condition is met
  attachInterrupt(digitalPinToInterrupt(PIRInterrupt), detectMotion, RISING);
  // Serial communication for debugging purposes
  Serial.begin(9600);
}

void loop() {
  // If 10 seconds have passed, the relay is turned off
  if((millis() - lastDebounceTime) > debounceDelay && relayState == HIGH){
    digitalWrite(relay, HIGH);
    relayState = LOW;
    Serial.println("OFF");
  }
  delay(50);
}

void detectMotion() {
  Serial.println("Motion");
  if(relayState == LOW){
    digitalWrite(relay, LOW);
  }
  relayState = HIGH;  
  Serial.println("ON");
  lastDebounceTime = millis();
}

                How-to-measure-distance-with-arduino Ultrasonic sensors are great tools to measure distance withou...