Skip to content

Instantly share code, notes, and snippets.

@AkbarAlam
Created August 22, 2016 13:09
Show Gist options
  • Save AkbarAlam/8c6152359fb13f93ac1ff444fb404949 to your computer and use it in GitHub Desktop.
Save AkbarAlam/8c6152359fb13f93ac1ff444fb404949 to your computer and use it in GitHub Desktop.
plant counting using ultrasonic sensor with bcm2835 lib
#include <stdio.h>
#include <bcm2835.h>
// defining the connections
#define ultra_LT RPI_V2_GPIO_P1_16
#define ultra_LE RPI_V2_GPIO_P1_18
void setup()
{
// setting the pins as output
bcm2835_gpio_fsel(ultra_LT, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(ultra_LE, BCM2835_GPIO_FSEL_INPT);
bcm2835_gpio_set_pud(ultra_LE, BCM2835_GPIO_PUD_UP);
}
// detacting plants
int main()
{
uint16_t num;
uint16_t sum=0;
while(1)
{
bcm2835_gpio_write(ultra_LT, HIGH);
bcm2835_delay(100);
bcm2835_gpio_write(ultra_LT, LOW);
bcm2835_delay(500);
bcm2835_gpio_read(ultra_LE, HIGH)=num;
while (num>0)
{
sum=sum+1;
printf("the current number of plants %d \n",sum);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment