Créer un site internet

Projets Electroniques

Ultrasonic Sensor made with NE555, Arduino Tutorial

31 08 2017 22 40 49

Télémètre à Ultrasons (PCB; Arduino)

12

Working Principle: 

Electrical control signal is sent to the ultrasonic transmitter E, the ultrasonic waves generated at 40 kHz is propagated and then reflected on an obstacle placed at a Distance d from the transmitter. This reflected wave is then recovered by a receptor R also placed at a distance d from the obstacle. The sound speed in the air is V = 340m / s, the electrical signal received by R will be delayed by a time t = 2d / v. It is therefore Possible by measuring the time difference between the control signal of the transmitter and the echo received by the receiver to easily calculate the distance d separating the obstacle of the sensor.

15

1. Transmission :

1.a) 40 kHz Astable Oscillator  (NE555)

 RA + 2RB = 1kOHM we can choose RA = 0.5 kΩ and  RB = 0.25 kΩ

 F=(1.44)/{(RA+RB )C} so >>> C = 36 nF

1 12 3

1.b) To make a delay in the NE555 output signal , We applie on the (RST) of the NE555 a pulse de 0-5 V (T = 10 ms, TH = 1ms) 

4 15 2

1.c) An amplifier block is then applied to the NE555 output. The two signals are in phase opposition, so when we sum the two signals we will 10V.

1 22 4

2. Reception :

2.a) Reception signal amplification: 

to obtain a signal centered around 2.5 between 0 and 5 we have V + = (R4 / (R3 + R4)) * Vcc Or Vcc = 5 therefore R4 / (R3 + R4) must be equal to 0.5 so R3 = R4.  We set R3 and R4 to 1Kohm. R1 and R2 are set to 1k to have Vout between 0 and 5 without reaching the limits with a gain between 0 and 10.

73 2

8

2.a) Filtre Block:

to produce a peak detector, it is necessary to have a good envelope function detection of the signal output , by applying :

τ = R5C2 = 10T

T = 1/F = 1 / 40kHz = 0,000025 s

and R5 = 1kΩ  

then C2 = 10T / R5 = (10x0,000025) / 1000 = 0,25 μF 

The capacitance C2 has been set to 0.07μF so that the signal is respected. Changing The capacitance affect the envelope of the signal. The lower it is the more the signal
is preserved,  if it is high, data are lost. (C2 / 100 and C2x100) are the extreme case , we must find a medium value to preserve the appearance of the Crete without having too violent peaks.

910

The received signal passes into the converter and is then transformed into a square signal. The more R6 is small, the length of the high state of the signal is great. By lowering the resistance R6 , it is possible to obtain a more precise signal, which further envelops the received signal.

1112 1

 

Code :

SensorSensor (194.97 Ko)

Communication Radio

Le module utilisé est le nRF24L01, il s’agit d’un module radio tout intégré fonctionnant sur la gamme de fréquences de 2.4GHz (comme le WiFi ou le Bluetooth). Il s'agit d'un module qui se comporte à la fois en émetteur et  récepteur. La vitesse de fonctionnement maximale est de 2 Mbps, avec une faible consommation électrique. La distance de transmission est relativement élevée et permet le pilotage de robots, la transmission à distance de données (alarmes, mesures de capteurs, périphériques d'ordinateurs...). Le module avec antenne incorporée (visible sur le circuit) peut transmettre sur environ 100 mètres Pour de plus longue portée (1 km) il existe des modules analogues mais amplifiés et avec une antenne plus grande, à brancher dessus.

Sans titre

L’objectif de la maquette et purement pédagogique et pourra être adapté à tous les niveaux, et ceci en introduisant les phénomène de génération des signaux, la modulation de largeur d'impulsion (MLI), Les bus de communication en série et plus précisément le bus SPI... . En effet, la liaison SPI (Serial Peripheral Interface) est une liaison série synchrone (bi-directionnelle) qui opère en mode full- duplex . Les circuits communiquent selon un schéma maître-esclaves, où le maître s'occupe totalement de la communication. Plusieurs esclaves peuvent coexister sur un même bus, dans ce cas, la sélection du destinataire se fait par une ligne dédiée entre le maître et l'esclave appelée Slave Select (SS).

Sans titre5

La carte a été réalisée via un logiciel de conception en ligne easyeda.com, ci-dessous les fichiers gerber des deux cartes ( émission / reception ):

Sans titre3

Gerber emetteur 20191128093753Gerber emetteur 20191128093753 (52.4 Ko)

Sans titre4

Gerber recepteur 20191128093605Gerber recepteur 20191128093605 (147.37 Ko)

 

Sans titre2

Code source:

/* Tranmsitter code for the Arduino Radio control with PWM output
 * Install the NRF24 library to your IDE
 * Upload this code to the Arduino UNO, NANO, Pro mini (5V,16MHz)
 * Connect a NRF24 module to it:
 
    Module // Arduino UNO,NANO
    
    GND    ->   GND
    Vcc    ->   3.3V
    CE     ->   D9
    CSN    ->   D10
    CLK    ->   D13
    MOSI   ->   D11
    MISO   ->   D12


*/

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

const uint64_t my_radio_pipe = 0xE8E8F0F0E1LL; //Remember that this code should be the same for the receiver

RF24 radio(9, 10);  //Set CE and CSN pins

// The sizeof this struct should not exceed 32 bytes
struct Data_to_be_sent {
  byte ch1;
  byte ch2;
  byte ch3;
  byte ch4;
  byte ch5;
  byte ch6;
  byte ch7;
};

//Create a variable with the structure above and name it sent_data
Data_to_be_sent sent_data;

void setup()
{
  radio.begin();
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);
  radio.openWritingPipe(my_radio_pipe);

  //Reset each channel value
  sent_data.ch1 = 127;
  sent_data.ch2 = 127;
  sent_data.ch3 = 127;
  sent_data.ch4 = 127;
  sent_data.ch5 = 0;
  sent_data.ch6 = 0;
  sent_data.ch7 = 0;
}

/**************************************************/


void loop()
{
  /*If your channel is reversed, just swap 0 to 255 by 255 to 0 below
  EXAMPLE:
  Normal:    data.ch1 = map( analogRead(A0), 0, 1024, 0, 255);
  Reversed:  data.ch1 = map( analogRead(A0), 0, 1024, 255, 0);  */
  
  sent_data.ch1 = map( analogRead(A0), 0, 1024, 0, 255);
  sent_data.ch2 = map( analogRead(A1), 0, 1024, 0, 255);
  sent_data.ch3 = map( analogRead(A2), 0, 1024, 0, 255);
  sent_data.ch4 = map( analogRead(A3), 0, 1024, 0, 255);
  sent_data.ch5 = digitalRead(2);
  sent_data.ch6 = digitalRead(3);
  sent_data.ch7 = map( analogRead(A4), 0, 1024, 0, 255);

  radio.write(&sent_data, sizeof(Data_to_be_sent));
}

/* Receiver code for the Arduino Radio control with PWM output
 * Install the NRF24 library to your IDE
 * Upload this code to the Arduino UNO, NANO, Pro mini (5V,16MHz)
 * Connect a NRF24 module to it:
 
    Module // Arduino UNO,NANO
    
    GND    ->   GND
    Vcc    ->   3.3V
    CE     ->   D9
    CSN    ->   D10
    CLK    ->   D13
    MOSI   ->   D11
    MISO   ->   D12


*/


#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>  //To create PWM signals we need this lybrary

const uint64_t pipeIn = 0xE8E8F0F0E1LL;     //Remember that this code is the same as in the transmitter
RF24 radio(9, 10);  //CSN and CE pins

// The sizeof this struct should not exceed 32 bytes
struct Received_data {
  byte ch1;
  byte ch2;
  byte ch3;
  byte ch4;
  byte ch5;
  byte ch6;
  byte ch7;
};

Received_data received_data;

Servo channel_1;
Servo channel_2;
Servo channel_3;
Servo channel_4;
Servo channel_5;
Servo channel_6;
Servo channel_7;

int ch1_value = 0;
int ch2_value = 0;
int ch3_value = 0;
int ch4_value = 0;
int ch5_value = 0;
int ch6_value = 0;
int ch7_value = 0;

void reset_the_Data() 
{
  // 'safe' values to use when NO radio input is detected
  received_data.ch1 = 0;      //Throttle (channel 1) to 0
  received_data.ch2 = 127;
  received_data.ch3 = 127;
  received_data.ch4 = 127;
  received_data.ch5 = 0;
  received_data.ch6 = 0;
  received_data.ch7 = 0;
}

/**************************************************/

void setup()
{
  //Attach the servo signal on pins from D2 to D8
  channel_1.attach(2);
  channel_2.attach(3);
  channel_3.attach(4);
  channel_4.attach(5);
  channel_5.attach(6);
  channel_6.attach(7);
  channel_7.attach(8);
  
  //We reset the received values
  reset_the_Data();

  //Once again, begin and radio configuration
  radio.begin();
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);  
  radio.openReadingPipe(1,pipeIn);
  
  //We start the radio comunication
  radio.startListening();

}

/**************************************************/

unsigned long lastRecvTime = 0;

//We create the function that will read the data each certain time
void receive_the_data()
{
  while ( radio.available() ) {
  radio.read(&received_data, sizeof(Received_data));
  lastRecvTime = millis(); //Here we receive the data
}
}

/**************************************************/

void loop()
{
  //Receive the radio data
  receive_the_data();

//////////This small if will reset the data if signal is lost for 1 sec.
/////////////////////////////////////////////////////////////////////////
  unsigned long now = millis();
  if ( now - lastRecvTime > 1000 ) {
    // signal lost?
    reset_the_Data();
    //Go up and change the initial values if you want depending on
    //your aplications. Put 0 for throttle in case of drones so it won't
    //fly away
  } 

  
  ch1_value = map(received_data.ch1,0,255,1000,2000);
  ch2_value = map(received_data.ch2,0,255,1000,2000);
  ch3_value = map(received_data.ch3,0,255,1000,2000);
  ch4_value = map(received_data.ch4,0,255,1000,2000);
  ch5_value = map(received_data.ch5,0,1,1000,2000);
  ch6_value = map(received_data.ch6,0,1,1000,2000);
  ch7_value = map(received_data.ch7,0,255,1000,2000);

  //Creathe the PWM signals
  channel_1.writeMicroseconds(ch1_value);  
  channel_2.writeMicroseconds(ch2_value);  
  channel_3.writeMicroseconds(ch3_value);  
  channel_4.writeMicroseconds(ch4_value);  
  channel_5.writeMicroseconds(ch5_value);  
  channel_6.writeMicroseconds(ch6_value);  
  channel_7.writeMicroseconds(ch7_value);  
  
  
}//Loop end

×