Un laboratorio sulle onde e.m.

Il 20 maggio 2017, in occasione del sabato museale Sapienza, abbiamo dato vita ad alcuni laboratori didattici per ragazzi. In uno di questi abbiamo imparato cosa sono le onde e.m. e come costruire una semplice trasmittente. Per produrre un’onda elettromagnetica di ampiezza variabile abbiam fatto così.

Per prima cosa si prende un oscillatore a cristallo di frequenza pari a 1 MHz (lo potete trovare su Internet a un prezzo che varia dai 3 ai 5 euro). Nell’oscillatore c’è un cristallo di quarzo che oscilla a frequenze fissate quando gli si applica una tensione, come quella di una pila. Il cristallo è contenuto in un contenitore metallico con quattro piedini, come nella figura.

IMG_20170517_120201.jpgIn basso a sinistra si nota un piccolo puntino scuro. Il puntino serve come riferimento per individuare i piedini utili, che sono gli altri tre. Collegando una pila da 9 V ai due piedini che si vedono nella figura sotto si fa oscillare il cristallo contenuto nel dispositivo.

IMG_20170517_120302.jpg

In uscita dal piedino in alto a destra della figura si può osservare un segnale a onda quadra con frequenza di 1 MHz di ampiezza costante. L’ampiezza di questo segnale dipende dalla tensione applicata. Se quindi facciamo variare la tensione applicata, varierà l’ampiezza del segnale in uscita. Osserviamo l’immagine sotto.

IMG_20170517_120442 La pila è stata posta in serie a un jack e l’uscita dell’oscillatore è stata collegata a un filo volante che fungerà da antenna. Inviando un segnale modulato in ampiezza al jack, la tensione di alimentazione dell’oscillatore varia da 9-V a 9+V, dove V è l’ampiezza del segnale in ingresso. Come segnale si può usare quello in uscita dalla presa cuffie di un PC che ha una frequenza compresa tra 20 e 20.000 Hz (quelle percepibili dall’orecchio umano), molto più bassa di quella dell’oscillatore.

quartz+sound

Supponiamo che il segnale del cristallo in presenza di tensione costante pari a 9 V sia quello rappresentato in viola nella figura superiore, mentre in ingresso al jack finisca un segnale come quello rappresentato nella parte bassa della figura.

Il risultato sarà che in uscita dall’oscillatore vedremo un segnale che è il segnale viola modulato in ampiezza da quello verde, come quello che si vede sotto.

convolution

Questo segnale variabile genera sul filo, che funge da antenna, un’onda e.m. che s’irradia nei dintorni. Mettendosi con un radio AM sintonizzata sulla frequenza di 1 MHz si può così ascoltare la musica che dal PC è irradiata dal dispositivo sotto forma di onde e.m. attraverso il jack inserito nella presa cuffie.

Un trasmettitore così funziona solo su distanze molto brevi, ma funziona, dimostrando la propagazione delle onde e.m..

Annunci

The School of Physics with Arduino and Smartphones is over

Our first school of physics with Arduino and Smartphones is finally over after three intense days and it was a success, indeed.

Physics teachers with no experience at all in programming, nor with Arduino, joined a class the first day for a crash course in Arduino programming, transducers and sensors, as well as on smartphones’ sensors usage.

img_20160912_114547

The second day of the school was divided in three parts: a design session during which teachers, in groups of two or three, were left free to design their own experiment, a shopping session when we went for shopping to buy materials needed for them and an implementation session during which the experiments were realised using the techniques learnt the day before.

IMG_20160913_121438.jpg

The third day experiments were refined and data analysed, then they were presented to other groups.

IMG_20160913_155923.jpg

Teachers were turned into makers in just two days, making amazing experiments aiming at studying the laws of motion, the Ohm’s law, the propagation of heat along a rod, the magnetic field produced by currents, the physics of non-inertial frames, the charge and discharge of a capacitor. Moreover they built a robot able to follow a line on the floor and a system to tell when a plant must be watered.

img_20160914_144650

Three fantastic days, in fact, much beyond expected!

Prosegue il lavoro della Scuola di Fisica con Arduino

Oggi giornata intensa alla Scuola di Fisica con Arduino e Smartphone. S’inizia con la progettazione degli esperimenti che permette di fare una lista di quel che serve per realizzarli. Poi tutti a fare shopping nel paradiso dello sperimentatore: il negozio di cinesi vicino alla Fondazione Mondo Digitale. Da Eva Shopping, che ci ha gentilmente consentito di invadere il suo negozio, troviamo tutto ciò che ci serve (e anche di più). Tornati al FabLab iniziamo a montare e dopo la pausa pranzo si mettono a punto tutti i dettagli per arrivare pronti all’appuntamento di domani, quando bisognerà presentare il lavoro svolto ai colleghi.

Le foto di oggi? Qui!

Smartphone Physics

Nei giorni scorsi abbiamo predisposto alcuni semplici esperimenti che si possono realizzare con uno smartphone. Gli esperimenti in questione riguardano lo studio dei sistemi di riferimento non inerziali e si possono realizzare grazie al fatto che su ogni dispositivo di questo tipo è presente un accelerometro che permette al telefono di sapere in quale posizione si trova (verticale, orizzontale, poggiato su un tavolo).

Per realizzare questi esperimenti usiamo un’App gratuita il cui nome è Wireless IMU, scritta da Jan Zwiener. IMU non sta per Imposta Municipale Unica, ma per Inertial Measurement Unit: il software trasmette attraverso una rete WiFi i dati dei sensori del telefono che contengono informazioni rilevanti al fine di determinarne la posizione.

Una volta installata la App io ho scritto un’applicazione Java che intercetta i dati trasmessi dal telefono e li usa, negli esempi che ho previsto, per mostrarne il grafico in funzione del tempo e registrarli su un file per un’analisi successiva. Il software è, naturalmente, libero e si può scaricare all’indirizzo https://bitbucket.org/organtin/wimu. Essendo scritto in Java il software può girare su qualunque PC, indipendentemente dal sistema operativo. Il fatto che il codice sorgente sia aperto permette a chiunque di modificarlo e di realizzare l’applicazione che crede.

Le applicazioni al momento previste sono Imu e ImuFreeFall. La prima si limita a fare un grafico delle tre componenti dell’accelerazione in funzione del tempo. Mettendo il telefono su una piattaforma girevole si vede come l’accelerazione lungo il raggio diventi non nulla. Il dispositivo infatti si troverà in un sistema non inerziale con una componente centrifuga dell’accelerazione. Per eseguire l’esperimento si può usare un vecchio giradischi. Fissate bene il telefono sulla superficie per evitare che scivoli via (un modo consiste nell’incollare una cover sulla superficie girevole e fissare il telefono su quest’ultima).

ImuFreeFall mostra il valore della componente y dell’accelerazione e il modulo di quest’ultima in funzione del tempo. L’applicazione si arresta automaticamente quando il telefono passa da accelerazione nulla ad accelerazione diversa da zero. Se si tiene il telefono in verticale, l’accelerazione misurata lungo questa direzione è quella di gravità: 9.8 ms-2. Nel momento in cui lo si lascia cadere quest’accelerazione passa improvvisamente ad assumere il valore zero. Il telefono, infatti, si trova in un sistema di riferimento non inerziale con accelerazione costante. Appena la caduta si arresta l’accelerazione torna ad assumere il valore normale e l’applicazione si ferma. In questo modo si può sperimentare l’effetto del famoso ascensore in caduta libera descritto sui libri di fisica, per il quale dubito che qualcuno voglia fare l’esperimento. Naturalmente, per evitare che l’esperimento si possa eseguire una sola volta, il telefono va fatto cadere su un’opportuna superficie che attutisca l’urto: un secchio pieno di cuscini o di fiocchi di polistirolo da imballaggio funziona perfettamente (basta avere buona mira o un’area di caduta molto ampia).

Using DC motors with Arduino

In one of my last posts I have shown how to drive a servo motor. Servo motors comes in two flavours: the standard servo motors can be set such that they reach a given position and maintain it; the continuous rotation servo can rotate continuously at a given speed.

DC motors are very similar to continuous rotation servo motors, in fact. With respect to the latter, DC motor technology is much simpler and, as a consequence, these motors are cheaper than servos. As suggested by their name, DC motors need just a DC voltage source to run, so there is no need to use any PWM pin. They just have two wires to be connected to a voltage source. The direction of rotation depend on how you connect the wires to the voltage source. Reversing the polarity of the power makes the motor run in the opposite direction. The speed of a DC motor depends on the applied voltage: the higher the voltage, the higher the speed. Motor specifications tell you in which voltage range it operates: below the minimum voltage the motor will probably do not move at all or they move with lot of difficulty; above the maximum voltage you seriously risk to damage it.

Some DC motor, as the one we used for our tests, comes with a gear embedded in their body: gears make the motors more powerful, but slower.

If, for any reason, you need to control the rotation of a DC motor using Arduino, in principle it would be enough to connect one of the motor leads to the GND pin and the other to any digital pin. Setting the pin to LOW the motor doesn’t move. Setting the pin to HIGH the motor runs if 5V is in its range. Given the fact that the direction of rotation depends on the polarity of the voltage, inverting the wires makes the motor rotate in the opposite direction.

In some cases, however, this very simple schema cannot work: manifestly it does not work if 5V are not enough to run the motor; moreover, the maximum current that an Arduino pin can provide is 40 mA (but it is recommended to not exceed 20 mA) and it may not be sufficient to run the motor. In those cases you need an external power source. You cannot use Arduino as the power source, but you can use it as the driver of the motor, controlling an external power source used to feed the motor. Suppose, for example, that you need at least 9V to run your motor. You can use Arduino to realise a sort of switch that stays open until a given digital pin is set to HIGH. As soon as that pin flips from LOW to HIGH, the switch closes and the motor is connected to the power source.

Of course you can use a relays to this purpose, but we are going to illustrate the use of a transistor to obtain the same result. Understanding how to use transistors is always a good idea, even if you are not going to use them: knowledge is power!

Transistors can be thought as a sort of switches. In fact transistors may act both as amplifiers as well as switches, depending on how they are polarised. If you want to understand how transistors work in a non technical manner you can read my article published on ‘The Physics Teacher‘ (Giovanni Organtini, “A flush toilet model for the transistor”, Phys. Teach. 50, 221 (2012); http://dx.doi.org/10.1119/1.3694073). In order to understand this post you don’t need to understand how transistor work: it is enough to know that they behave like a switch. The switch connects the transistor emitterwith its collector and its operation is driven by its base. Consider the following circuit.

 

DCmotorCircuitSchema.png

The Arduino board is used just to provide a digital signal on a given pin (pin 9 in the example). This pin is connected to a resistor (whose value is not very important: its purpose is just to limit the current flowing out of the pin) that, in turn, is connected to the base of a transistor. If no current flows to the transistor base, the transistor is said to be in interdiction and acts as an open switch between the emitter and the collector. In our schema the motor is connected to a 9V battery trough the transistor, but you can imagine the transistor being substituted by an open switch. The Arduino ground is in common with the 9V minus lead.

As soon as you make enough current flowing into the transistor base, the transistor goes in saturation and acts as a closed switch. In that case the transistor emitter (the lower lead with the arrow in the schema) appears to be short circuited with its collector (the top lead, connected to the motor). In this case the current can flow from the battery and feed the motor that starts running.

Below you can see a Fritzing model of the device where you can see that the base of the transistor is its central lead; the emitter is on the left, while the collector is on the right

DCmotorCircuit.png

Below you can see our actual setup.

IMG_20160317_183148.jpg

In order to identify the collector, the base and the emitter of a transistor you must refer to its data sheet. There are common rules among producers, allowing you to identify the leads looking at the transistor shape (the one shown in the picture above is called TO-92). However, it is always a good idea to check the pinout on the specific transistor data sheet, because not all the manufacturers may use the same pinout for the same enclosure. The actual pinout, in fact, depends also on the transistor type.

There are two types of transistors: NPN and PNP. Transistors are made out of three semiconductor slices and semiconductors comes in two flavours: N-type and P-type semiconductors. In N-type semiconductors the current carriers are electrons, while in P-type semiconductors the current is due to holes (lack of electrons). In NPN transistors the base is made of a P-type semiconductor, while in PNP ones the base is an N-type semiconductor.

In the above example we showed how to use an NPN transistor. If you are going to use a PNP one, you should connect the collector to the positive lead of the battery and the emitter to the motor, while the second lead of the motor goes directly to ground.

Working with motors

In certain cases you may need to use motors for different purposes. Depending on the experiment or the device you are building, the type of motor to use can be different. In this series of posts I will show you how to use those motors with Arduino.

Servo Motors

Servo motors are motors for which you can control accurately enough the speed and the angle of rotation. They can be used to precisely move parts in your device. For examples, in physics experiment you can use a servo motor to hold a ball in a given position and release it at a given time to study its motion.

As most of the motors, servo motors can just rotate around their axis. However, with a bit of mechanics you can realise any kind of movement. To have an idea of what you can do with a rotating axis and some mechanics, just read the article on http://makezine.com/2015/04/20/understand-1700-mechanical-linkages-helpful-animations/.

Controlling a servo motor is incredibly easy with Arduino. Servo motors have three wires: usually coloured in black, red and white. The black one must be connected to the GND pin of the Arduino, while the red one to the 5V pin. They are used to feed the motor with some power. The third wire is used to control it. Any servo motor works receiving voltage pulses of a given width. Pulses are repeated at regular intervals (e.g. 20 ms), while the duration of a single pulse determines the rotation angle of the motor around its axis or its speed.

Given the working principle of a servo motor, you will not be surprised to know that you need to connect the control wire to one of the PWM (Pulse Width Modulation) pins of Arduino. PWM pins can be configured such that they provide voltage pulses at given interval with the chosen duty cycle. The duty cycle of a PWM pin is the faction of time for which the pin is at its highest voltage. An excellent tutorial on PWM pins is given here.

Putting the pin to zero makes the PWM pin to stay off, while putting it at its maximum value of 255 makes the pin to stay always on, i.e. with a duty cycle of 100%. In order to observe a square wave on the pin you must put it at 128, such that f=128/255=0.5 and the duty cycle is 50%. Any other number makes the pin to produce a square wave whose pulse width ranges from 0 to T, where T depends on the Arduino flavour. On the Arduino UNO T is about 2 ms.

With Arduino you don’t need to compute the values yourself to control a servo motor. The Servo library is in fact available for use and provides all the relevant configurations automatically. Consider the following sketch:

Servo myservo;

void setup() {
  myservo.attach(9);
}

void loop() {
  myservo.write(90);
  delay(1500);
  myservo.write(0);
  delay(1500);
}

The attach() method in setup() just tells Arduino to which pin the motor is attached, represented by the object myservo, defined as a member of the main class (Servo myservo). In the example the servo is attached to pin 9. You can then provide an angle, in degrees, to the write() method. Its effect depends on which type of servo motor you have.

There are, in fact, two types of servo motors: continuous rotation and standard. The write() command makes a standard servo rotate of the specified angle. A call to

  myservo.write(90);

with a standard servo makes it rotate of 90 degrees. With the above sketch a servo of this type rotates of 90 degrees, then holds that position for 1.5 s, before returning at its initial position, where it stays for 1.5 s. Being in the loop the above rotations are repeated continuously.

When a servo motor of this type is powered and is receiving a train of pulses, it resists to forces applied to it holding its position. Of course you cannot apply forces too large, if you do not want to damage your servo. The maximum torque you can exert on the servo axis is one of the characteristics you can find on the servo data sheet.

The maximum torque is usually measured in kg·cm and is the product of the mass of a weight suspended at a given distance on a beam mounted on the motor axis. Using a servo whose maximum torque is 10 kg·cm you can suspend 10 kg at a distance of 1 cm from the axis as well as 1 kg at 10 cm. The larger the distance, the lower the weight the servo can tolerate. Needless to say, it is not a good idea to use a servo close to its limit. If you need a given torque, choose a servo that can tolerate at least twice that torque.

In order to compute the torque in N·cm it is enough to multiply the torque in kg·cm by 9.8, i.e. by the gravitational acceleration. In this case a servo whose maximum torque is 10 kg·cm can tolerate a force acting 1 cm far from the axis of 10·9.8=98 N, or a force of 9.8 N acting at a distance of 10 cm from the axis.

Continuos rotation servo motors, instead, rotate clockwise or anticlockwise until they are powered. The number passed to the write() method represents the rotation speed: numbers from 0 to 89 make the motor axis rotate anticlockwise (seen from above), while numbers from 91 to 180 make it rotating clockwise. The maximum speed is attained for 0 or 180. The higher the number, the slower the speed if the number is less than 90. On the contrary, if the number is larger than 90, the speed increases with the number. Setting the speed at 90 makes the servo stop rotating. In the above sketch, then the servo rotates anticlockwise for 1.5 s, then stops for other 1.5 s and so on.

Here you can find the motor we used for our tests, but it is plenty of them in the Farnell Electronics store. Here is a video showing our continuous rotation servo working with the sketch outlined above.

This post appears on the Element14 Arduino Blog, who partly sponsored it, and its content will be included in my Scientific Arduino publication.

 

The RC circuit

This time I am going to share with you an amazingly simple experience that is made possible using just an Arduino UNO board, a resistor and a capacitor. The RC circuit is a classic circuit in physics teaching and is composed by just a resistor R and a capacitor C in series. For details you can look at the Charging a Capacitor page of the HyperPhysics pages. Pupils study the charging and discharging of the capacitor when the circuit is connected to a battery. A rather simple mathematics gives the laws governing the process. It is easy to show that the voltage across the capacitor VC is a function of the time t: when the capacitor is not charged and is connected to a voltage V0 through the resistor, one gets

VC(t)=V0(1et/θ)

Here  θ is a parameter having the dimensions of a time called the time constant of the circuit and is given by the product RC. When the capacitor is at its full charge and the two leads of the circuit are short circuited, the voltage across the capacitor drops with time with an exponential law whose time constant is still given by RC.

In the past, making the experience in a physics laboratory, was not so easy for students. The time constants that one can get using easily available components are short. For R of the order of few tens of kΩ and C of the order of few μF, the time constant is of the order of 10×103×10-6≈10-2s, i.e. a hundredth of a second. In order to measure the voltage across the capacitor as a function of time you need to connect the leads of a multimeter to the capacitor and read its value as a function of time, so you need time constants of the order, at least, of few seconds. That requires extremely large values of C (and R) that, of course, are not impossible to obtain, but are not so easy to find. Even in this case you can only collect few values.

With an Arduino board the job is greatly simplified and, needless to say, the precision you can attain with it is impressive.

The circuit, shown in the picture below (made with Fritzing), is easily realised connecting one of the leads of the resistor to the 5V pin of Arduino; the resistor is mounted in series with the capacitor that, in turn, has its second lead to the ground (GND). In order to measure the voltage across the capacitor, we connect the first lead of the capacitor to one of the Arduino analog inputs (A5).

 

RC.png

Initially, the red wire is not connected to the 5V pin and the capacitor is not charged. Using the new Arduino IDE one can plot the values written to the Serial monitor as a function of time (in fact as a function of the reading). Consider the following code:

void loop() {
  while (fabs(analogRead(A5)*5/1024. - lastReading) < 0.1) {
    // do nothing
  }
  for (int i = 0; i < 480; i++) {
    float currentReading = analogRead(A5)*5/1024.;
    Serial.println(currentReading);
  }
  while (1) {
    // do nothing
  }
}

The first loop just waits until the current reading of the A5 pin (analogRead(A5)) differs from the value of lastReading for more than one tenth of a volt. The fabs function returns the absolute value of its argument. The reading of the analog input can be an integer number between 0 and 1024 representing a voltage ranging from 0 to 5 V. Multiplying the reading by 5 and dividing it by 1024 we then get the value of the voltage across the capacitor in Volts. Note the dot after 1024 that is needed to make the value a floating point number. If the dot is missing, both 5 and 1024 are represented as integers in the Arduino memory, as well as the value returned by analogRead(A5). This can lead to important consequences. Suppose, for example, that the analogRead(A5) function returns 123. Once multiplied by 5, we get 615 that, divided by 1024 gives just zero! In fact, 615/1024 is a ratio between two integers and the result is interpreted as an integer, too. Writing 615/1024. (with the dot after 1024) forces the CPU to represent the number 1024 as a floating point number and any operation made using an integer (615) and a floating point number (1024.) is a floating point number (about 0.6).

The value of lastReading must be set in the setup() of the Arduino sketch, in which we also initialise the Serial monitor with

Serial.begin(9600);

The first loop, then, is needed to start the program as well as the Serial plotter, having the time to connect the red wire to the 5V pin. Only when such a wire is connected to that pin the capacitor starts charging and the voltage across its leads starts raising. At this point we just read a fixed number of values of such a voltage (480 in our case) and write them on the Serial monitor. Each value written to the Serial monitor is shown on the Serial plotter versus time (in fact each value written to the Serial monitor is plotted against a sequential number, but in our case the readings are made at almost constant intervals of time, hence the horizontal axis values are proportional to time).

Once we read all the values we just stop doing anything with the last loop. The result is shown below.

arduino-charge-RC.png

Such a very nice curve is exactly what we expected. You can even measure the discharge curve just repeating the experience in the following way: once charged, the capacitor remains charged until it is short circuited on the resistor. So, just disconnect the red wire from the 5V pin, restart the program and the Serial plotter, and connect the free lead of the red wire to the ground. The capacitor starts discharging on the resistor and the voltage across it changes. Soon after, the program makes 480 readings of the voltage and plot them, as can be seen below.

arduino-discharge-RC.png

You can even be more quantitative with a slight change into the Arduino sketch. Consider the following:

float lastReading;
unsigned long time;

void setup() {
  Serial.begin(9600);
  lastReading = analogRead(A5)*5/1024.;
}

void loop() {
  while (fabs(analogRead(A5)*5/1024. - lastReading) < 0.1) {
    time = micros();
  }
  for (int i = 0; i < 480; i++) {
    unsigned long now = micros(); 
    Serial.print(now - time);
    Serial.print(" ");
    float currentReading = analogRead(A5)*5/1024.;
    Serial.println(currentReading);
  }
  while (1) {
    // do nothing
  }
}

At the beginning of the loop we still wait for a change in the voltage, but in this case we collect the current time in the time variable. The current time is given by the micros() function returning the number of microseconds elapsed since the start of the sketch. As soon as the voltage changes we start measuring the voltages across the capacitor, but in this case we also get the time of each measurement and send to the Serial monitor both the time elapsed since the start of the measurements and the measurement values.

We write those two numbers to the Serial monitor, then copy and paste them into a text file for subsequent analysis. The picture below shows the data collected by us, during the charge:

RC.png

Times are in microseconds and you can see how rapid is the process. The capacitor is almost at its full charge already after 2 seconds. We used a resistor whose resistance was R=9.94 kΩ. We can then get the value of the capacitor from these measurements. With some mathematics one obtains a time constant θ of 0.53 s, from which we can derive C as θ/R≈54 μF. The nominal value of the capacitor we used is 47 μF. The error in the determination of it is then less than 15%.

This post appears on the Element14 Blog too, and is partly sponsored by Farnell Electronics. It will also appear in my free e-book on Scientific Arduino for teachers and students.