Skip to main content

Featured

RELAY

RELAY A relay is like a switch that can be controlled electronically. Relays are very simple devices and can be used to control devices with higher loads(Like AC controlled devices and devices that require heavy voltages to operate). Relay modules can be used mainly in IOT projects and home automation. Relays can be used to make useful hobby projects.  A two channel relay. *Dealing with high voltages may cause injuries or even death, please use relays with utmost care. Working of Relays. Relays work like electromagnets, when a voltage is applied the coil,  the coil gets charged and acts like an electromagnet and moves the switch to the desired position. In simple terms, relays act as magnets when a signal is applied or removed. Basic circuit of a relay Connections. +5V of Arduino-  5V of relay module. GND of Arduino- GND of relay module. Pin no. 8 of Arduino- In1 of relay module. Basic connection of a relay module CODE void setup() { pinMode(8, OUTPUT); } void loop() { digitalWrite(8,

Arduino Codes Basics

Some statements to know before arduino coding

There are few sentences of code that you are expected to know before arduino coding,
I’ll discuss some of them here and furthermore if I use any statement unknown to you I’ll give you people a legend that says what it does or leave a comment in the code.

The two main blocks of arduino code

There are two main blocks in arduino coding, named setup and loop.
The most common statements used in SETUP block are 


pinMode(some PIN number, OUTPUT/INPUT);

So what this statement does is, sets a pin to input mode or output mode.
In OUTPUT mode the arduino sends data to the external sensor or motor or whatever you are working with.
In INPUT mode the arduino receives data from the external sensor or any other thing.
 Over all we set that pin on the board to input mode or output mode using the above statement.

Serial.begin(9600);
 The above statement just begins communication between the arduino and the control unit(A phone or an ir remote or some input or output device).
9600 is the speed with which we have to communicate with the arduino(that’s the only speed it can communicate at).

*The variables must be given data types in or before this block.
Eg. int a;
Where int is the data type and a is the variable.
  
In the LOOP block the most common statements used are 

digitalWrite(some PIN number, HIGH);

  • This statement helps us write a PIN number to high output or 5V output(the Arduino can provide only 5V or 0V)
  • This statement is mainly used in programs that aim to run anything from turning on an LED to playing with motors.
analogWrite(some PIN number, 0-255);

  • This statement is similar to the previous statement but here we can specify output voltage from  0 to 255.

Serial.read();

  • This statement is used to read the data sent or received through the serial communication .
*There are a lot more statements that are used that we will learn as we go further 

Comments

Popular Posts