Beginners Tutorials with sample codes - Part 5 CloudX

  • img
Project Details

1. Light Intensity Control

Brief Description

In this project, we’ll make use of a Light Dependent Resistor (LDR) to detect the presence and intensity of Light in a particular area, and thus, use the received data to control the light intensity of an LED. 

 

Wiring

 

Code

#include <CloudX/ADC.h>  
#include <CloudX/PWM.h>

int LDRValue; //creates a variable for placing a whole number
//or integer

setup(){
//setup here

Analog_setting(); //configures and initializes the
//CloudX Analog Pins for Use

PWM1_init(5000); //configures the CloudX PWM module 1
PWM1_start(); //starts PWM Module 1 Operation.
PWM1_duty(0); //sets PWM duty cycle to 0

loop(){
//Program here

LDRValue = Analog_read(A0); //reads analog signal at A0
//and store value in
//LDRValue

//converts LDRValue’s value to percentage
LDRValue = ((float)LDRValue / 1023) * 100;

PWM1_duty(LDRValue); //sets PWM duty cycle with the
//value inside LDRValue

}
}
 

 

Simulation

 

 

 

2. LM35 Temperature Sensor 

Brief Description

For this project, we’ll take reading from the LM35 Temperature Sensor, and display the data on an LCD Module. 

 

Wiring

 

Code

#include <CloudX\ADC.h>  
#include <CloudX\LCD.h>
#include <CloudX\conversion.h> //necessary for the float to
//string conversion


float temperatureReading; //storage for placing non-whole number
//or fraction

char *temperatureDisplay; //creates pointer variable

//------------------------------------------------------
//Degree-Symbol Custom character code generated from the
//CloudX Custom Generator
//------------------------------------------------------
const char degreeSign[] = {6, 9, 9, 6, 0, 0, 0, 0};

setup(){
//setup here

LCD_setting (1, 2, 3, 4, 5, 6); //RS,EN,D4,D5,D6,D7
Analog_setting();
LCD_cmd(clear);
LCD_writeText(1, 3, "TEMP. READING");
//shows " TEMP. READING" on LCD

loop(){
temperatureReading = Analog_read(A0);//reads data from
//analog input pin0

//converts raw sensor value to its Celsius scale value
temperatureReading = temperatureReading * 500 / 1023;

//converts float value in temperatureReading to string
temperatureDisplay = floatTostr(temperatureReading);

temperatureDisplay[5] = 0; //controls string to contain
//only five characters

LCD_writeText(2, 1, "Value: "); //writes to LCD

//displays content in temperatureDisplay in the Current
//Cursor Position of the LCD
LCD_writeTextCP(temperatureDisplay);

//------------------------------------------------------
//The below function-call writes the degree custom-
//character,(stored in CGRAM address 00), at the LCDs
//current cursor position (CP).
//------------------------------------------------------
LCD_writeCustomChar(0, 0, 0, degreeSign);
//CGRAMAddress, row, col, customCharacter

//displays single character in the Current Cursor
//Position of the LCD
LCD_writeCP('C');

}
}

 

Simulation

 

 

3. Motion Sensor 

Brief Description

For this project, we’ll use a Passive Infrared (PIR) Sensor to sense motion, and display the info on an LCD Module. 

 

Also, we’ll use a buzzer sound to signal the presence of the detected Motion. 

PIR Sensor Specifications

Commonly used for motion detection.

Detecting range: 7m (700cm) 

  • Cover range: 110°

 

Caveat:

There must be a relative motion…

 

PIR Sensor Pin-out

 

Wiring

 

Code

#include <CloudX/LCD.h>  

#define PIR 7
#define Buzzer 8
#define LED 9

setup(){
//setup here

pinMode(PIR, INPUT);
pinMode(Buzzer, OUTPUT);
pinMode(LED, OUTPUT);
LCD_setting (1, 2, 3, 4, 5, 6); //RS,EN,D4,D5,D6,D7
LCD_cmd(clear);
LCD_writeText(1, 1, "MOTION DETECTOR");

loop(){
//Program here

//Execute this section of code, if the motion sensor
//senses ANY movement.
if (readPin(PIR) is HIGH)
{
digitalWrite(Buzzer, HIGH); //turns buzzer on
digitalWrite(LED, HIGH); //turns LED on
LCD_writeText(2, 1, "STATUS: Present ");
//displays "STATUS: Present " on LCD
}

//Execute this section of code, if the motion sensor
//senses NO movement
else
{
digitalWrite(Buzzer, LOW); //turns buzzer off
digitalWrite(LED, LOW); //turns LED off
LCD_writeText(2, 1, "STATUS: Absent");
//displays "STATUS: Absent" on LCD
}
}
}

 

Simulation

 

 

4. Smoke or Gas Detector 

Brief Description

In this project, we’ll check out for smoke or gas leakage via a Smoke Detector, and control the state of a buzzer, a Red LED and a Green LED with respect to the sensor’s Output. 

Wiring

 

Code

#define DO        1  
#define Buzzer 2
#define RedLED 3
#define GreenLED 4

setup(){
//setup here

pinMode(DO, INPUT);
pinMode(Buzzer, OUTPUT);
pinMode(RedLED, OUTPUT);
pinMode(GreenLED, OUTPUT);


loop(){
//Program here

//Execute this section of code, if the Smoke sensor
//senses smoke or gas.
if (readPin(DO))
{
digitalWrite(Buzzer, HIGH); //turns buzzer on
digitalWrite(RedLED, HIGH); //turns RedLED on
digitalWrite(GreenLED, LOW); //turns GreenLED off
}

//Execute this section of code, if the Smoke sensor does
//not sense smoke or gas.
else
{
digitalWrite(Buzzer, LOW); //turns buzzer off
digitalWrite(RedLED, LOW); //turns RedLED off
digitalWrite(GreenLED, HIGH); //turns GreenLED on
}
}
}

 

Simulation

 

You can drop comment below.

Share this with friends