Arduino Pmod LS1

Arduino Pmod LS1

Application notes for Pmod LS1 and Arduino Uno. The input voltage and output level of the comparator module is displayed in serial monitor.

  • 309 views
  • 0 comments
  • 2 respects

Components and supplies

About this project

This application note was designed to change the output voltage of the Pmod DPOT (digital potentiometer) from 0 to 5 V and the comparator module returns a high level if the voltage is greater than threshold. The input voltage and output level of the comparator module is displayed in the serial monitor.

Good Luck!

Code

CodeArduino
/************************************************************************
*
* Test of Pmod LS1
*
*************************************************************************
* Description: Pmod_LS1
* The output voltage of the digital potentiometer module changes from 0 to 5 V
* And the comparator module returns a high level if the voltage is
* Greater than threshold.
* The input voltage and output level of the comparator module is displayed
* In the serial monitor.
*
*
* Material
* 1. Arduino Uno
* 2. Pmod DPOT
* 3. Pmod LS1
*
************************************************************************/

#define CS 10 // Assignment of the CS pin
#define comparateur 2 // Assignment of the comparator pin
#include <SPI.h> // call library

int i;
int val=0;
float tension;

void setup()
{
 Serial.begin(9600); // initialization of serial communication
 SPI.begin(); // initialization of SPI communication
 SPI.setDataMode(SPI_MODE0); // configuration of SPI communication in mode 0
 SPI.setClockDivider(SPI_CLOCK_DIV16); // configuration of clock at 1MHz
 pinMode(CS, OUTPUT);
 pinMode(comparateur, INPUT);
}

void loop()
{
 for (i=0;i<256;i=i+1)
   {
   digitalWrite(CS, LOW); // activation of CS line
   delayMicroseconds(15);
   SPI.transfer(i); // Send variable i (i=0->Vout=0V i=255->Vout=Vcc)
   val=analogRead(A0); // conversion AN
   tension = map(val, 0, 1023, 0, 5000); // Voltage varies from 0 to 5000 for a variation of val from 0 to 255
   tension=tension/1000;
   Serial.print("i=");
   Serial.print(i);
   Serial.print('\t'); // tabulation
   Serial.print("val=");
   Serial.print(val);
   Serial.print('\t'); // tabulation
   Serial.print("Tension=");
   Serial.print(tension);
   Serial.println("V");
   digitalWrite(CS, HIGH); // deactivation of CS line
   if (digitalRead(comparateur)==HIGH)
   {
    Serial.println("La sortie du comparateur est au niveau haut");
   }
   else
   {
    Serial.println("La sortie du comparateur est au niveau bas");
   }
   delay(200);
   }
}

Comments

Add projectSign up / Login