Category Archives: Arduino

FLAMELESS ELECTRONIC CANDLE USING ARDUINO

In this we will see how to make a flameless electronic candle using Arduino. Believe me this is so much fun making this. The way a real candle looks it looks the same as it. You can use it for many decorative purposes.

As these are electronic candles this is flame less a best alternative to real candles. So Diwali the festival of light is coming soon and enjoy an eco friendly Diwali with a flameless candle.

COMPONENTS REQUIRED

S.N. COMPONENT QUANTITY
1. Arduino UNO 1
2. Arduino Cable 1
3. Breadboard 1
4. LED Yellow 2
5. LED Red 1
6. Resistor 220 Ω 3

EXPLANATION

The project of electronic candle is based on PWM concept, if you don’t know about PWM take a brief – PWM stands for pulse width modulation, we know LED is a diode and works only in forward direction, but there is a twist, although it works is forward direction but if I give the led a less voltage it will be appears to be dim.

Same as this if I vary this voltage level then the intensity of the LED will also vary. In simple terms LED receives a DC cycle of different duty cycles (ON period). See figure

PWM signals of different duty cycles
PWM signals of different duty cycles

Take 3 LEDs, 1 Red and 2 Yellow to get the illusion of a real candle. Connect it to Arduino as shown in figure. Cover up Led with an opaque box or something like that but keep the top side a little open for light to come out.

CONNECTION DIAGRAM

Flameless Electronic Candle using arduin
Click to Zoom

 

CONNECTION TABLE 

Arduino LED’s Anode (+)
9 1st Yellow Led
10 1st Red Led
11 2nd Yellow Led

 

Arduino LED’s Cathode (–)
GND 1st Yellow Led
GND 1st Red Led
GND 2nd Yellow Led

ARDUINO CODE FLAMELESS ELECTRONIC CANDLE

/* Tutorial: https://pijaeducation.com/flameless-electronic-candle-using-arduino
*/

int led1 = 9;
int led2 = 10;
int led3 = 11;
int fix = 60;
int vary = 195;
void setup() {
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
}

void loop() {
  analogWrite(led1, random(vary) + fix);
  analogWrite(led2, random(vary) + fix);
  analogWrite(led3, random(vary) + fix);
}

CODE EXPLANATION FLAMELESS ELECTRONIC CANDLE 

In void setup (), Firstly define pin mode of Arduino pins that are 9, 10 and 11 as Output.

In void loop (), For PWM we are using function analogWrite (pinNumber, Intensity). Intensity can be varied from 0 to 255. One more function we are using is random (int_number), this means it will get random value from 0 to 195 and added by 60 to make 255, you can vary random number 195 (like “random(160)+90”) according to your convenience or requirement.

Here we are using another inbuilt function of arduino that is random() which is used for generating random numbers

SYNTAX
random(max)
random(min, max)

Returns: a random number between minimum and maximum-1 (long data type) 

OUTPUT 

Total Visits: 2574

SERVO MOTOR WITH ARDUINO

In this section, you learn interfacing of servo motor with Arduino, but before this let’s start with servo motor.

A servo motor is an electrical device used to rotate objects at certain specified angles. It’s just a basic motor that runs through the mechanism of the servo.

They are used in numerous applications such as toy cars, robotics, machines etc.

Servo motors are measured in kg / cm (kilogram per centimeter). Servo motors are rated 3kg / cm or 6kg / cm etc. This kg / cm tell you how much weight your servo engine can lift at a given distance. Generally servo motor 9G SG90 is used in projects.

Servo Motor

For example – If the load is suspended 1 cm away from the shaft of the motors, a 3kg / cm Servo motor will be able to lift 3 kg, the greater the distance the less the ability to carry weight. Electrical pulse determines the direction of a servo motor.

COMPONENTS REQUIRED

S.N. COMPONENT QUANTITY
1. Arduino Uno 1
2. Servo Motor SG90 1
3. Jumper wires 3

SERVO MOTOR PINOUT

Servo Motor pinout

WIRE CONFIGURATION

Wire Number Wire Colour Description
1. Brown Ground wire connected to the ground of system
2. Red Powers the motor typically +5V is used
3. Orange PWM signal is given in through this wire to drive the motor

SERVO MOTOR SG90 TECHNICAL FEATURES

    • Operating Voltage is +5V
    • Torque: 2.5kg/cm
    • Operating speed is 0.1s/60°
    • Gear Type: Plastic
    • Rotation : 0°-180°
    • Weight of motor : 9gm
    • Package includes gear horns and screws

HOW SERVO MOTOR WORKS

Servo motors have 3 wires coming out of them. Out of which 2 are used as Power pins (positive and negative) and the third one is used for the signal that is to be sent from the MCU.

All Servo motors operate on the principle of PWM (Pulse Width Modulation), meaning their angle of rotation is controlled by the length of the pulse applied to their Control PIN. Essentially, the servo motor consists of a DC motor powered by a variable resistor (potentiometer – POT) and some gears.

PWM signals of different duty cycles
PWM signals of different duty cycles

Servo motor SG90 can be rotated from 0 to 180 degree, but other servo motors can rotate completely 360 degree depending upon manufacturer. By adding the correct width of the Electrical Pulse to its control pin, this degree of rotation can be controlled.

CIRCUIT DIAGRAM – SERVO MOTOR ARDUINO

To interface servo motor with Arduino make connections like this. PWM supported pins in Arduino Uno are 3, 5, 6, 9, 10, and 11 (~ tilde sign before pin).

Servo motor with Arduino

CONNECTION TABLE

S.N. Arduino Servo Motor
1. +5V VCC (red)
2. GND GND (brown)
3. 9 Signal (orange)

SERVO MOTOR ARDUINO CODE

/*Tutorial: https://pijaeducation.com/servo-motor-with-arduino/
*/
// PWM supported pins in Arduino Uno are 3, 5, 6, 9, 10, and 11.

#define del 15
// include servo library, don't need to install externally already available in arduino IDE
#include <Servo.h>
// create servo object to control a servo
Servo myservo;

void setup() {
  /* Attaches servo variable myservo to pin 9.
    Using myservo you can use servo library inbuilt function, which control servo connected on pin 9
  */
  myservo.attach(9);
  Serial.begin(9600);
}

void loop() {
  // rotate servo motor from 0 to 180 degree
  for (int i = 0 ; i <= 180 ; i++) {
    // set servo motor angle to value i
    myservo.write(i);
    // prints i value to serial monitor
    Serial.println(i);
    delay(del);
  }

  // rotate servo motor from 180 to 0 degree
  for (int i = 180 ; i >= 0 ; i--) {
    myservo.write(i);
    Serial.println(i);
    delay(del);
  }

  // Earlier we attached servo to pin 9, here we can detach it if needed. Not compulsory to do here.
  // myservo.detach();
}

CONNECT MORE SERVO MOTORS

/*Tutorial: https://pijaeducation.com/servo-motor-with-arduino/
*/
// If you want to connect more servo motor then you need to create more servo variables like

#include <Servo.h>
Servo myservo1;
Servo myservo2;

void setup() {
  myservo1.attach(9);
  myservo2.attach(10);
  Serial.begin(9600);
}

OUTPUT

Motor will start rotation from 0 to 180 degree, but these motors are not so accurate, so there are chances the motor can move 15-20 degree less.

Servo motor with Arduino

Total Visits: 1206