Posts Tagged ‘arduino’

Class : Technology

Software : Arduino IDE

Equipment : Arduino UNO Board, HC-05 Bluetooth Module, Breadboard, Jumper Wires, Fan

Challenges :
  • Making proper connections from Arduino to the components.
  • Understanding the Rx and Tx connections from Bluetooth Module to Arduino.
  • Programming the code.


Approach:

To advance with our projects here in Shukhov Lab, it was necessary for us to learn how to operate and program the Arduino boards and perform basic activities. In this project I was trying to work with an Arduino and bluetooth module setup for controlling a DC Motor (A fan in this case) using a smartphone.

  Process: First it is required to assemble all components together and make the connections.

 

I have initially connected the bluetooth module to the breadboard and made necessary connections to the arduino board using male-male jumper cables.

 

The connection for the bluetooth module are as follows:

BLUETOOTH    –           ARDUINO

Txd  –  Rx

Rxd  –  Tx

Gnd  –  Gnd

Vcc  –  3.3V

 

Next I connected the DC powered fan to the arduino and connected it with GND for the negative terminal and PIN-8 for the positive terminal.

I chose pin 8 here because I have activated it in the code using the statement (int ledpin = 8;)

The connections to the arduino board are shown on the image below:



Finally we upload the developed code to the arduino board.

*NOTE:
  • It is very important to disconnect the Rx and Tx cables from the bluetooth module before uploading the code or it might display an error.
  • Always disconnect the arduino power source before making any wiring changes to avoid short circuit.
  The code which I used can be found below:

char val;

int ledpin = 8;

void setup() {

pinMode(ledpin, OUTPUT);

Serial.begin(9600);

}

void loop() {

if( Serial.available() )

{

val = Serial.read();

}

if( val == ‘H’ )

{

digitalWrite(ledpin, HIGH);

} else {

digitalWrite(ledpin, LOW);

}

delay(100);

}



  I have also downloaded an application on my phone, from which I can send signal to the Bluetooth module.

It is necessary to download this app or a similar app. You can download one from the link below:

https://apkpure.com/arduino-bluetooth-controller/com.giumig.apps.bluetoothserialmonitor/download?from=details  

After uploading the code, I disconnected the power from arduino board connected back the Rx and Tx cables and plugged back the power source into the arduino (it can be from your notebook’s USB or via 5V power adaptor)

Next I opened my bluetooth settings in my phone and paired the device with bluetooth module HC-05.

*NOTE: 
  •  In case of password prompt, use – 1234
  •  Typing H on the bluetooth app activates signal and typing anything else switches it off.


Then open the app (arduino bluetooth controller) and select the device (HC-05) from the list of paired devices and connect with the switch or terminal modes as shown below. In my case I have used the Switch mode and set the parameters for ON button as “H” and OFF button as “X”. Otherwise you can manually use the Terminal mode.



The fan rotates on sending the signal “H” (ON) and switches off on sending signal “X” (OFF) successfully.

It is demonstrated in the video below:

   

Class: Technology, Arduino

 

Hardware:

  • Arduino Uno
  • Breadboard Circuit
  • Jumper Wires
  • DHT11 sensor x 1
  • Mini Servo Motor x 2
 

Software:

  • Arduino
 

Task:

The idea was to program servo motors to rotate according to humidity and temperature as an input. I used two servo motors and DHT 11 sensor. When temperature gets higher than 26c, servos start rotating for 180, when the temperature goes down, they rotate back.

Assembly:

I prepared all the components. After I began to wire them, actually it took much time, because I didn’t know how how to do that. I started searching on www.instructables.com for similar projects, i found some and began to create the code. When I finished it all worked well, servos were rotating according to the temperature and humidity. I was really proud of myself. You can check my code at the end of the post.

 



Arduino Uno code servo DHT11  
Class: Technology, Arduino
Software: Arduino 1.8.5
Materials:
  • 1 Arduino Uno card
  • 1 solderless breadboard
  • 1 bipolar transistor
  • 1 LED scale
  • 1 1 kΩ resistor
  • 4 resistors with a rating of 220 Ohm
  • 8 wires “Male-male”

SCHEMATIC DIAGRAM

VIDEO OF PROCESS

SCETCH OF CODE

#define CONTROL_PIN  9
int brightness = 0;
void setup()
{  pinMode(CONTROL_PIN, OUTPUT);
}
void loop()
{  brightness = (brightness + 1) % 256;
  analogWrite(CONTROL_PIN, brightness);
  delay(10);
}
 

FINAL RESULT

The Smart cube project requires a complicated code which connects the MPU-6050 gyroscope with bluetooth and 5 objects: 2 home lights made from LED and RGB strip lights , 2 servo motors-door lock and curtain blinders and ventilaton- 12 Volts USB fan.

The code logic is: the gyroscope has different angles in each face of Smart Cube,  when turning on Z axis the other axis not changing , but Z axis, which means different axis in each point, but for user it is same logic- turn left or right on Z axis and change it’s settings- speed, direction, power. The logic of this is to change  change the supply voltage while rotating the cube.

  • The first idea for the code:

int led= ; //led at pin int ledValue; //value of led int ledFadeAmount = 5; //value when led is fading

void setup() {

pinMode(led, OUTPUT); //led specified as output Serial.begin(2400); //starting serial at 2400 baud BSens.begin(); //initialize the ADXL345 sensors_event_t event; //collect data from ADXL345 BSens.getEvent(&event); //read data from ADXL345 float pos = event.acceleration.x; //test purpose for determining position of x. Future use.

}

void ledFadeIn(){ //function of fade from 16 to 255

sensors_event_t event; BSens.getEvent(&event);

if (event.acceleration.z > -8.50 | event.acceleration.z < -10.00){ //if z position is greater than -8.50 or x is smaller than -10.00 ledValue = ledValue + ledFadeAmount; //set led value to the sum of led value and fade amount if(ledValue > 255) //if led value is greather than 255 ledValue = 255; //set led value to 255. Stops looping between led value 16 and 255. analogWrite(led, ledValue); //analog write of led value to led (pin 9) delay(30); //delay of 30 ms then start the ledfadein again }

}

void ledFadeOut(){ //function of fade from 255 to 16

sensors_event_t event; //collect data from ADXL345 BSens.getEvent(&event); //read data from ADXL345

if (event.acceleration.z < -8.50 | event.acceleration.z > -10.00){ //if z position is smaller than -8.50 or x is larger than -10.00 ledValue = ledValue – ledFadeAmount; //set led value to the sum of led value minus the fade amount if(ledValue < 16) //if led value is smaller than 255 ledValue = 16; //set led value to 16. Stops looping between led value 255 an analogWrite(led, ledValue); //analog write of led value to led (pin 9) delay(30); //delay of 30 ms then start the ledfadeout again }

}

void loop() {

sensors_event_t event; //collect data from ADXL345 BSens.getEvent(&event); //read data from ADXL345 float pos = event.acceleration.x; //test purpose for determining position of x. Future use. Serial.println(ledValue); //print value of led in the Serial Monitor

if (event.acceleration.z > -8.50 | event.acceleration.z < -10.00) //if z position is greater than -8.50 or x is smaller than -10.00 ledFadeIn(); //goto the ledFadeIn function else ledFadeOut(); //goto the ledFadeIn function

}

  • The final code has two variations:
  • Code made for DF Robot Bluno Beetle, which is very miniature arduino with easy to connect and fast Bluetooth 4.0
  • Code made to connect Arduino with HC-05 Bluetooth modules.

Here the codes shown:

  • Bluno send code with objects and gyroscope settings:

#include <Wire.h>

#include <MPU6050.h>

MPU6050 sensor(0x68) ;

int16_t motion_x, motion_y, motion_z , rotation_x, rotation_y, rotation_z ;

int16_t gx, gy, gz ;

int s=0;

byte flag_x1, flag_x2, flag_y1, flag_y2, flag_z1, flag_z2;

void setup ( )

{ Wire.begin ( );

Serial.begin (19200);

//Serial.println ( “Initializing the sensor” );

sensor.initialize ( );

//Serial.println (sensor.testConnection ( ) ? “Successfully Connected” : “Connection failed”);

//delay (1000);

//Serial.println ( “Taking Values from the sensor” );

//delay (1000); s=0; flag_x1=0; flag_x2=0; flag_y1=0; flag_y2=0; flag_z1=0; flag_z2=0; }

void loop ( )

{ sensor.getRotation (&rotation_x, &rotation_y, &rotation_z); sensor.getMotion6 (&motion_x, &motion_y, &motion_z, &gx, &gy, &gz); rotation_x = map (rotation_x, -16000, 16000, 0, 255) ; rotation_y = map (rotation_y, -16000, 16000, 0, 255) ; rotation_z = map (rotation_z, -16000, 16000, 0, 255) ;

motion_x = map (motion_x, -16000, 16000, 0, 255) ; motion_y = map (motion_y, -16000, 16000, 0, 255) ; motion_z = map (motion_z, -16000, 16000, 0, 255) ;

if ((motion_z>200)&&(motion_x>=120)&&(motion_y>=120)) // включается управление объектом №1 {

if (flag_z1 ==0) { Serial.println (1000); // Число объекта №1 flag_z1 =1; flag_z2=0; flag_x1=0; flag_x2=0; flag_y1=0; flag_y2=0; } if (rotation_z<110) { if (s<255) { s+=5; } else { s=255; }

} else if (rotation_z>150) { if (s>0) { s-=5; } else { s=0; }

} Serial.println (s); }

else if ((motion_z<50)&&(motion_x>=120)&&(motion_y>=120)) // // включается управление объектом №2 { if (flag_z2==0) { Serial.println (1001); // Число объекта №2 flag_z2=1; flag_z1=0; flag_x1=0; flag_x2=0; flag_y1=0; flag_y2=0; } if (rotation_z>150) { if (s<180) // разворот сервомотора { s+=5; } else { s=180; }

} else if (rotation_z<110) { if (s>0) { s-=5; } else { s=0; }

} Serial.println (s); }

if ((motion_y>200)&&(motion_x>=120)&&(motion_z>=120)) // включается управление объектом №3 { if (flag_y1 ==0) { Serial.println (1010); // Число объекта №3 flag_y1 =1; flag_y2=0; flag_x1=0; flag_x2=0; flag_z1=0; flag_z2=0; } if (rotation_y<110) { if (s<255) { s+=5; } else { s=255; }

} else if (rotation_y>150) { if (s>0) { s-=5; } else { s=0; }

} Serial.println (s); } else if ((motion_y<50)&&(motion_x>=120)&&(motion_z>=120)) // // включается управление объектом №4 { if (flag_y2==0) { Serial.println (1011); // Число объекта №4 flag_y2=1; flag_y1=0; flag_x1=0; flag_x2=0; flag_z1=0; flag_z2=0; } if (rotation_y>150) { if (s<255) //увеличение яркости { s+=5; } else { s=255; }

} else if (rotation_y<110) { if (s>0) { s-=5; } else { s=0; }

} Serial.println (s); } if ((motion_x>200)&&(motion_y>=120)&&(motion_z>=120)) // включается управление объектом №5 { // Свободная грань } else if ((motion_x<50)&&(motion_y>=120)&&(motion_z>=120)) // // включается управление объектом №6 { if (flag_x2 ==0) { Serial.println (1100); // Число объекта №1 flag_x2 =1; flag_x1=0; flag_y1=0; flag_y2=0; flag_z1=0; flag_z2=0; } if (rotation_x<110) { if (s<255) { s+=5; } else { s=255; }

} else if (rotation_x>150) { if (s>0) { s-=5; } else { s=0; }

} Serial.println (s); }

// az = map (az, -16000, 16000, 0, 255) ; /*if (s<255) { sensor.getRotation (&ax, &ay, &az); az = map (az, -16000, 16000, 0, 255) ; if (az>150) { s+=5; } } if (s>0) { sensor.getRotation (&ax, &ay, &az); az = map (az, -16000, 16000, 0, 255) ; if (az<80) { s-=5; } } Serial.println (s); */ /*Serial.print (ax); Serial.print (‘;’); Serial.print (ay); Serial.print (‘;’); Serial.print (az); Serial.println (‘;’);*/

//sensor.getMotion6 (&ax, &ay, &az, &gx, &gy, &gz); //ax = map (ax, -16000, 16000, 0, 255) ; //ay = map (ay, -16000, 16000, 0, 255) ; //az = map (az, -16000, 16000, 0, 255) ; //Serial.print (ax); //Serial.print (‘;’); //Serial.print (ay); //Serial.print (‘;’); //Serial.print (az); //Serial.println (‘;’);

//sg90.write (ax);

delay (1); }

  • Bluno receive code with commans to smart home objects:

//Bluno_Receiver_AT+SETTING=DEFCENTRAL or AT+SETTING=DEFPERIPHERAL #include <VarSpeedServo.h>

VarSpeedServo myservo1, myservo2; byte object;

void setup() { Serial.begin(19200); object=0; pinMode(3, OUTPUT); pinMode(5, OUTPUT); // pinMode(5, OUTPUT) myservo1.attach(2); myservo2.attach(4); myservo1.write(0,50); myservo2.write(0,50); }

void loop() { while (Serial.available() > 0) { int inCommand = Serial.parseInt(); switch (inCommand) { case 1000: object=1; break; case 1001: object=2; break; case 1010: object=3; break; case 1011: object=4; break; case 1100: object=5; break; case 1101: object=6; break; }

if (object==1) { // Serial.println(inCommand); //analogWrite(2,inCommand); myservo1.write(inCommand, 50);

} if (object==2) { // Serial.println(inCommand); analogWrite(3,inCommand); } if (object==3) { // Serial.println(inCommand); //analogWrite(4,inCommand); myservo2.write(inCommand, 50); } if (object==4) { // Serial.println(inCommand); analogWrite(5,inCommand); } if (object==5) { // Serial.println(inCommand); analogWrite(A0,inCommand); }

} }

  • The Bluno receive module has been broken and the problem was to make another connection with bluetooth or other tool of connection: The radio module has been tried to use , but it doesn’t work on streaming mode and HC-05 bluetooth modules has been connected with Arduino Nano and UNO.
  • Here the final code of the Smart Cube device:

#include <Wire.h> #include <SoftwareSerial.h> #include <MPU6050.h>

MPU6050 sensor(0x68) ;

int16_t motion_x, motion_y, motion_z , rotation_x, rotation_y, rotation_z ;

int16_t gx, gy, gz ;

int s=0;

byte flag_x1, flag_x2, flag_y1, flag_y2, flag_z1, flag_z2;

SoftwareSerial mySerial(2, 3); // RX, TX void setup ( )

{ Wire.begin ( );

Serial.begin (115200); mySerial.begin(38400); //Serial.println ( “Initializing the sensor” );

sensor.initialize ( );

//Serial.println (sensor.testConnection ( ) ? “Successfully Connected” : “Connection failed”);

//delay (1000);

//Serial.println ( “Taking Values from the sensor” );

//delay (1000); s=0; flag_x1=0; flag_x2=0; flag_y1=0; flag_y2=0; flag_z1=0; flag_z2=0;

}

void loop ( )

{ sensor.getRotation (&rotation_x, &rotation_y, &rotation_z); sensor.getMotion6 (&motion_x, &motion_y, &motion_z, &gx, &gy, &gz); rotation_x = map (rotation_x, -16000, 16000, 0, 255) ; rotation_y = map (rotation_y, -16000, 16000, 0, 255) ; rotation_z = map (rotation_z, -16000, 16000, 0, 255) ;

motion_x = map (motion_x, -16000, 16000, 0, 255) ; motion_y = map (motion_y, -16000, 16000, 0, 255) ; motion_z = map (motion_z, -16000, 16000, 0, 255) ;

if ((motion_z>200)&&(motion_x>=120)&&(motion_y>=120)) // включается управление объектом №1 {

if (flag_z1 ==0) { mySerial.println (1000); // Число объекта №1 Serial.println (1000); flag_z1 =1; flag_z2=0; flag_x1=0; flag_x2=0; flag_y1=0; flag_y2=0; } if (rotation_z<110) { if (s<255) { s+=5; } else { s=255; }

} else if (rotation_z>150) { if (s>0) { s-=5; } else { s=0; }

} mySerial.println (s); }

else if ((motion_z<50)&&(motion_x>=120)&&(motion_y>=120)) // // включается управление объектом №2 { if (flag_z2==0) { mySerial.println (1001); // Число объекта №2 flag_z2=1; flag_z1=0; flag_x1=0; flag_x2=0; flag_y1=0; flag_y2=0; } if (rotation_z>150) { if (s<180) // разворот сервомотора { s+=5; } else { s=180; }

} else if (rotation_z<110) { if (s>0) { s-=5; } else { s=0; }

} mySerial.println (s); }

if ((motion_y>200)&&(motion_x>=120)&&(motion_z>=120)) // включается управление объектом №3 { if (flag_y1 ==0) { mySerial.println (1010); // Число объекта №3 flag_y1 =1; flag_y2=0; flag_x1=0; flag_x2=0; flag_z1=0; flag_z2=0; } if (rotation_y<110) { if (s<255) { s+=5; } else { s=255; }

} else if (rotation_y>150) { if (s>0) { s-=5; } else { s=0; }

} mySerial.println (s); } else if ((motion_y<50)&&(motion_x>=120)&&(motion_z>=120)) // // включается управление объектом №4 { if (flag_y2==0) { mySerial.println (1011); // Число объекта №4 flag_y2=1; flag_y1=0; flag_x1=0; flag_x2=0; flag_z1=0; flag_z2=0; } if (rotation_y>150) { if (s<255) //увеличение яркости { s+=5; } else { s=255; }

} else if (rotation_y<110) { if (s>0) { s-=5; } else { s=0; }

} mySerial.println (s); } if ((motion_x>200)&&(motion_y>=120)&&(motion_z>=120)) // включается управление объектом №5 { // Свободная грань } else if ((motion_x<50)&&(motion_y>=120)&&(motion_z>=120)) // // включается управление объектом №6 { if (flag_x2 ==0) { mySerial.println (1100); // Число объекта №1 flag_x2 =1; flag_x1=0; flag_y1=0; flag_y2=0; flag_z1=0; flag_z2=0; } if (rotation_x<110) { if (s<255) { s+=5; } else { s=255; }

} else if (rotation_x>150) { if (s>0) { s-=5; } else { s=0; }

} mySerial.println (s); } Serial.println (s); // az = map (az, -16000, 16000, 0, 255) ; /*if (s<255) { sensor.getRotation (&ax, &ay, &az); az = map (az, -16000, 16000, 0, 255) ; if (az>150) { s+=5; } } if (s>0) { sensor.getRotation (&ax, &ay, &az); az = map (az, -16000, 16000, 0, 255) ; if (az<80) { s-=5; } } Serial.println (s); */ /*Serial.print (ax); Serial.print (‘;’); Serial.print (ay); Serial.print (‘;’); Serial.print (az); Serial.println (‘;’);*/

//sensor.getMotion6 (&ax, &ay, &az, &gx, &gy, &gz); //ax = map (ax, -16000, 16000, 0, 255) ; //ay = map (ay, -16000, 16000, 0, 255) ; //az = map (az, -16000, 16000, 0, 255) ; //Serial.print (ax); //Serial.print (‘;’); //Serial.print (ay); //Serial.print (‘;’); //Serial.print (az); //Serial.println (‘;’);

//sg90.write (ax);

delay (1); }

  • The code for receive device:

#include <VarSpeedServo.h> #include <SoftwareSerial.h> VarSpeedServo myservo1, myservo2; SoftwareSerial mySerial(10, 11); // RX, TX byte object;

void setup() { Serial.begin(115200); mySerial.begin(38400); object=0; pinMode(3, OUTPUT); pinMode(5, OUTPUT); pinMode(9, OUTPUT); // pinMode(5, OUTPUT) myservo1.attach(2); myservo2.attach(4); myservo1.write(0,50); myservo2.write(0,50);

}

void loop() { while (mySerial.available()) { int inCommand = mySerial.parseInt(); Serial.println(inCommand); switch (inCommand) { case 1000: object=1; break; case 1001: object=2; break; case 1010: object=3; break; case 1011: object=4; break; case 1100: object=5; break; case 1101: object=6; break; }

if (object==1) { // Serial.println(inCommand); //analogWrite(2,inCommand); myservo1.write(inCommand, 50);

} if (object==2) { // Serial.println(inCommand); analogWrite(3,inCommand); } if (object==3) { // Serial.println(inCommand); //analogWrite(4,inCommand); myservo2.write(inCommand, 50); } if (object==4) { // Serial.println(inCommand); analogWrite(5,inCommand); } if (object==5) { // Serial.println(inCommand); analogWrite(9,inCommand); }

} }

ARDUINO/

Class: 

Technology, Arduino

Software:

  • Arduino IDE
  • web browser

Hardware:

  • Arduino Uno R3
  • Breadboard, Diode
  • Resistor 220om
  • Wires
  • Push-button

Task:

To create input/output device based on Arduino. 

Realization: 

To complete the task, I used the base schema and code from the site www.instructables.com. This is easy enough if you follow the steps of the link. First, I assembled the schema manually from the components, then copied the code and uploaded it into the board. If everything is assembled correctly and there are no errors, everything will work. Now that my code is working, I can program the crab as I need it. Important to disconnect arduino and your laptop during you remove whatever on the broad)))  
Class: Technologies
Software used: Arduino IDE, web browser
Device used: Arduino Uno
Components used: Diode, resistor 220om, wires, push-button x 2

address: 20 Myasnitskaya ulitsa
(metro stations ‘Lubyanka’ and ‘Kitay-Gorod’)
Moscow 101000 Russia

phone: +7(495)772-95-90 *15026

email: city@hse.ru