Posts Tagged ‘arduino’

Task:

Create an Arduino cirquit + write a program, using 2 components (LED, button, light sensor, servo etc.)

Components:

I decided to explore how to use a digit 7-segment digit, so that it could count the number of times I press the button.
  • Arduino UNO + cable
  • 14 jumper wires (male-male)
  • Common cathode 7-segment display
  • Button
  • 2 resistors, 220 ohm
  • Breadboard

Piece of theory:

How does the display work? Well, seven segment displays is just 7 LEDs, connected together. They are  called segments,and are arranged in the shape of an “8”. Most 7-segment displays actually have 8 segments, with a dot on the right side of the digit that serves as a decimal point. Each segment is named with a letter A to G, and DP for the decimal point:     Single digit seven segment displays typically have 10 pins. Two pins connect to ground, and the other 8 connect to each of the segments. Here is a pin diagram of the one that I used:    

Assembling:

Connect the pins described below:
  1. Arduino Pin 2 to Pin 9.
  2. Arduino Pin 3 to Pin 10.
  3. Arduino Pin 4 to Pin 4.
  4. Arduino Pin 5 to Pin 2..
  5. Arduino Pin 6 to Pin 1.
  6. Arduino Pin 8 to Pin 7.
  7. Arduino Pin 9 to Pin 6.
  8. GND to Pin 3 and Pin 8 each connected with 220 ohm resistors.

Code:

const int a = 8; //For displaying segment "a"
const int b = 9; //For displaying segment "b"
const int c = 4; //For displaying segment "c"
const int d = 5; //For displaying segment "d"
const int e = 6; //For displaying segment "e"
const int f = 2; //For displaying segment "f"
const int g = 3; //For displaying segment "g"

bool bPress = false;
const int buttonPin = 10;

// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button

void setup() {
// put your setup code here, to run once:
pinMode(a, OUTPUT); //A
pinMode(b, OUTPUT); //B
pinMode(c, OUTPUT); //C
pinMode(d, OUTPUT); //D
pinMode(e, OUTPUT); //E
pinMode(f, OUTPUT); //F
pinMode(g, OUTPUT); //G

pinMode( buttonPin , INPUT_PULLUP );
Serial.begin(9600);
displayDigit(buttonPushCounter);
}

void loop() {

buttonState = digitalRead(buttonPin);

// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == LOW) {
// if the current state is HIGH then the button went from off to on:
bPress = true;
buttonPushCounter++;
if( buttonPushCounter > 9) buttonPushCounter =0 ;
Serial.println("on");

} else {
// if the current state is LOW then the button went from on to off:
Serial.println("off");
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state, for next time through the loop
lastButtonState = buttonState;

if( bPress ){
turnOff();
displayDigit(buttonPushCounter);
}

}

void displayDigit(int digit)
{
//Conditions for displaying segment a
if(digit!=1 && digit != 4)
digitalWrite(a,HIGH);

//Conditions for displaying segment b
if(digit != 5 && digit != 6)
digitalWrite(b,HIGH);

//Conditions for displaying segment c
if(digit !=2)
digitalWrite(c,HIGH);

//Conditions for displaying segment d
if(digit != 1 && digit !=4 && digit !=7)
digitalWrite(d,HIGH);

//Conditions for displaying segment e
if(digit == 2 || digit ==6 || digit == 8 || digit==0)
digitalWrite(e,HIGH);

//Conditions for displaying segment f
if(digit != 1 && digit !=2 && digit!=3 && digit !=7)
digitalWrite(f,HIGH);
if (digit!=0 && digit!=1 && digit !=7)
digitalWrite(g,HIGH);

}
void turnOff()
{
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}







Results:

In the end I got a cirquit, where the display shows numbers from 0 to 9, which represent how many times the button was pressed.  
  • Class: Technology.
  • Software: Arduino.
  • Material/details: Cardboard, Male/male jumper wires, Breadboard, Arduino Uno, Blue LEDs x6, Resistors (1 k ohm) x6, Photoresistor, Resistor (10 k ohm).
  • Aim: Explore Arduino and learn how to program in Arduino Language.
 
  • Process:

For this task, I decided to make simple snowflake which consists of 6 Blue LEDs. The idea is that LEDs turn on when lights in the room are turned off. In order to make it, I was needed to solder LEDs to the jumper wires and connect everything via breadboard to the Arduino (cathode to the ground and anode to the pins). I was not able to show it in the scheme, but for LEDs I used 1 k ohm resistors and for the Photoresistor 10 k ohm resistor.

   

I was needed to make a code which will work for the snowflake. At the start, I listed all components (six LEDs and one photoresistor). Then, in “void setup” I listed what is going to be input and what is an output. In the “void loop” I create the algorithm for a lighted and non-lighted environment. “int ldrStatus” reads the values of Photoresistor. In my case I used ldrStatus <=300, however, this number can be changed.

  • Code for snowflake:

const int ledPin1 = 8;

const int ledPin2 = 9;

const int ledPin3 = 10;

const int ledPin4 = 11;

const int ledPin5 = 12;

const int ledPin6 = 13;

const int ldrPin = A0;

 void setup() {

  pinMode(ledPin1, OUTPUT);

  pinMode(ledPin2, OUTPUT);

  pinMode(ledPin3, OUTPUT);

  pinMode(ledPin4, OUTPUT);

  pinMode(ledPin5, OUTPUT);

  pinMode(ledPin6, OUTPUT);

  pinMode(ldrPin, INPUT);

}

void loop() {

  int ldrStatus = analogRead(ldrPin);

   if (ldrStatus <=300) {

    digitalWrite(ledPin1, HIGH);

    digitalWrite(ledPin2, HIGH);

    digitalWrite(ledPin3, HIGH);

    digitalWrite(ledPin4, HIGH);

    digitalWrite(ledPin5, HIGH);

    digitalWrite(ledPin6, HIGH);

    Serial.println(“LDR is DARK, LED is ON”);

   }

  else {

    digitalWrite(ledPin1, LOW);

    digitalWrite(ledPin2, LOW);

    digitalWrite(ledPin3, LOW);

    digitalWrite(ledPin4, LOW);

    digitalWrite(ledPin5, LOW);

    digitalWrite(ledPin6, LOW);

    Serial.println(“—————“);

  }

}

  •   Result:

Task:

create a program for Arduino, using 2 or more familiar details (LEDs, button, Servo, photoresistor)

Hardware:

Software:

Arduino

The idea was to create a circuit, using Servo and LED, in a way that potentiometer would control the rotation of the servo as well as the brightness of LED.

I started with the tests of circuits with servo and LED separately.

Onwards, I have tried to get them together in one unit.

I combined each of the blocks (‘define’, void setup, void loop) and it worked out perfectly.

 

Here is how the circuit works:

And the program itself:

 
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)))  

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

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

email: city@hse.ru